/// 实名认证数据模型
class RealnameAuthData {
  final int userid;
  final int authStatus;
  final String statusMsg;
  final bool verified;
  final String flowId;
  final String authTime;
  final String idCardNo;

  RealnameAuthData({
    required this.userid,
    required this.authStatus,
    required this.statusMsg,
    required this.verified,
    required this.flowId,
    required this.authTime,
    required this.idCardNo,
  });

  /// 从JSON创建实例
  factory RealnameAuthData.fromJson(Map<String, dynamic> json) {
    return RealnameAuthData(
      userid: json['userid'] ?? 0,
      authStatus: json['authStatus'] ?? 0,
      statusMsg: json['statusMsg'] ?? '',
      verified: json['verified'] ?? false,
      flowId: json['flowId'] ?? '',
      authTime: json['authTime'] ?? '',
      idCardNo: json['idCardNo'] ?? '',
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'userid': userid,
      'authStatus': authStatus,
      'statusMsg': statusMsg,
      'verified': verified,
      'flowId': flowId,
      'authTime': authTime,
      'idCardNo': idCardNo,
    };
  }

  @override
  String toString() {
    return 'RealnameAuthData(userid: $userid, authStatus: $authStatus, statusMsg: $statusMsg, verified: $verified, flowId: $flowId, authTime: $authTime, idCardNo: $idCardNo)';
  }
}

/// 实名认证响应模型
class RealnameAuthResponse {
  final String status;
  final String message;
  final RealnameAuthData? data;

  RealnameAuthResponse({
    required this.status,
    required this.message,
    this.data,
  });

  /// 从JSON创建实例
  factory RealnameAuthResponse.fromJson(Map<String, dynamic> json) {
    return RealnameAuthResponse(
      status: json['status'] ?? '',
      message: json['message'] ?? '',
      data: json['data'] != null ? RealnameAuthData.fromJson(json['data']) : null,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'message': message,
      'data': data?.toJson(),
    };
  }

  /// 是否请求成功
  bool get isSuccess => status == 'success';
  
  /// 是否认证失败
  bool get isError => status == 'error';
  
  /// 是否已认证
  bool get isVerified => data?.verified ?? false;
  
  /// 认证状态描述
  String get authStatusDescription {
    if (data == null) return message;
    
    switch (data!.authStatus) {
      case 0:
        return '未认证';
      case 1:
        return '认证中';
      case 2:
        return '认证成功';
      case 3:
        return '认证失败';
      default:
        return data!.statusMsg;
    }
  }
  
  /// 脱敏后的身份证号
  String get maskedIdCard => data?.idCardNo ?? '';
  
  /// 认证时间
  String get authTime => data?.authTime ?? '';
  
  /// 流程ID
  String get flowId => data?.flowId ?? '';

  @override
  String toString() {
    return 'RealnameAuthResponse(status: $status, message: $message, data: $data)';
  }
}